package com.kolon.business.mServiceDesk.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.kolon.framework.constant.Constant;
import com.kolon.framework.interfaces.SimpleController;
import com.kolon.framework.util.ComUtil;
import com.kolon.framework.util.MsgUtil;

@Controller("com.kolon.business.mServiceDesk.controller.MServiceDeskDeadLineController")
public class MServiceDeskDeadLineController implements SimpleController {

	@SuppressWarnings("rawtypes")
	@RequestMapping(value="/business/mServiceDesk/mServiceDeskDeadLine.do")
	public ModelAndView controller(HttpServletRequest request,
		HttpServletResponse response) throws Exception {
		// 도메인
		String url = MsgUtil.getMessage("xml.url");
		// 세션 아이디 및 암호 값을 불러옴
		HttpSession httpSession = request.getSession();
		Map userMap = (Map)httpSession.getAttribute(Constant.SESSION_USER_INFO);
		String id = (String)userMap.get("userId");
		String pw = (String)userMap.get("userPw");
		//권한을 새션에 호출
		HttpSession session = request.getSession(true);
		String assignee = (String)session.getAttribute("SESSION_ASSIGNEE");
		String approval = (String)session.getAttribute("SESSION_APPROVAL");
		String ref_num = request.getParameter("Ref_Num");
		String ref_type = request.getParameter("Ref_Type");
		String returnUrl = "/business/mServiceDesk/mServiceDeskProcessView.do?Ref_Num="+ref_num +"&Ref_Type="+ref_type;
		ModelAndView modelAndView = new ModelAndView();
		//요청 등록하기
		if(!"".equals(request.getParameter("nabgi_desc")) && request.getParameter("nabgi_desc")!=null && !"".equals(request.getParameter("nabgi_date")) && request.getParameter("nabgi_date")!=null) {
			StringBuffer buffer2 = new StringBuffer();
			buffer2.append(url);
			buffer2.append("/servicedesk.aspx?mode=").append("action");
			buffer2.append("&actionMode=").append("3");
			buffer2.append("&ref_num=").append(ref_num);
			buffer2.append("&nabgi_desc=").append(ComUtil.getEncode(request.getParameter("nabgi_desc"),"EUC-KR"));
			buffer2.append("&nabgi_date=").append(request.getParameter("nabgi_date"));
			buffer2.append("&userid=").append(id);
			// XML DOCUMENT 및 인증 처리
			ComUtil.getDocument(buffer2.toString(), id, pw);
			modelAndView.addObject("message", "요청자에게 메일이 전송되었습니다.");
			modelAndView.addObject("scriptType", "003");
			modelAndView.addObject("message_url", returnUrl);
			modelAndView.setViewName("/business/common/alert");
		}
		modelAndView.addObject("assignee", assignee);
		modelAndView.addObject("approval", approval);
		modelAndView.addObject("Ref_Num", ref_num);
		modelAndView.addObject("Ref_Type", ref_type);
		return modelAndView;
	}	
	
}